<div>
    <div class="col-lg-12">
        <div class="panel panel-default">
            <div class="panel-body">
                <div style="float: left;margin-top: -20px;">
                    <h3><a href="/setting/staff-create" class="btn btn-success pull-right">增加员工</a></h3>
                </div>
                <div class="col-md-1 align-right">
                    <button type="submit" class="btn btn-primary" onclick="saveStaff()"><i class="fa fa-search"></i> 筛选</button>
                </div>
                <div class="col-md-2 align-right">
                    <input type="text" placeholder="请输入员工姓名/账号/联系电话" class="form-control" value="<?php echo $this->search_text;?>" id="condition">
                </div>
                <div class="col-md-1 align-right">
                    <select name="" id="status" class="form-control">
                        <option value="">全部状态</option>
                        <option value="1" <?php echo $this->is_use == '1' ? 'selected' : '';?>>开启</option>
                        <option value="0" <?php echo $this->is_use == '0' ? 'selected' : '';?>>禁用</option>
                    </select>
                </div>
            </div>
            <div class="panel-body">
                <section id="no-more-tables">
                    <table class="table table-bordered table-striped table-condensed cf">
                        <thead class="cf">
                        <tr>
                            <td>序号</td>
                            <td>账号</td>
                            <td>姓名</td>
                            <td>联系电话</td>
                            <td>角色</td>
                            <td>状态</td>
                            <td>备注</td>
                            <td>操作</td>
                        </tr>
                        </thead>
                        <tbody>
                            <?php if(!empty($this->list)){?>
                                <?php foreach ($this->list as $k=>$v){?>
                                    <tr>
                                        <td><?php echo $k+1;?></td>
                                        <td><?php echo $v['account'];?></td>
                                        <td><?php echo $v['name'];?></td>
                                        <td><?php echo $v['tel'];?></td>
                                        <td><?php echo $v['enterprise_role_id'] == 1 ? '管理员' :'业务员';?></td>
                                        <td><?php echo $v['is_use'] == 1 ? '启用' :'禁用';?></td>
                                        <td><?php echo $v['remark'];?></td>
                                        <td>
                                            <button class="btn btn-default" type="button"  data-toggle="modal" onclick="edit(<?php echo $v['id']?>);">编辑</button>
                                            <?php if($v['is_use'] == 1){?>
                                            <button class="btn btn-default" type="button"  data-toggle="modal" onclick="forbid(<?php echo $v['id']?>,0);">禁用</button>
                                            <?php }else{?>
                                            <button class="btn btn-default" type="button"  data-toggle="modal" onclick="forbid(<?php echo $v['id']?>,1);">启用</button>
                                            <?php }?>
                                        </td>
                                    </tr>
                                <?php }?>
                        <?php }?>
                        </tbody>
                    </table>
                    <?php echo $this->page;?>
                </section>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    function edit(e) {
        window.location.href = '/setting/staff-edit?id=' + e;
    }
    function saveStaff() {
        var searchValue = $("#condition").val();
        searchValue = escape(searchValue);
        var is_use = $("#status").val();
        var queryString = '?';
        if (searchValue != '') {
            queryString += '&searchText=' + searchValue;
        }
        if (is_use != '') {
            queryString += '&is_use=' + is_use;
        }
        queryString = queryString.substr(2, queryString.length);
        window.location.href = '/setting/staff-list?' + queryString;
    }
    function forbid(id,status) {
        var ms="";
        if(status == 1){
            ms="确认要启用该账号？";
        }else{
            ms="确认要禁用该账号？";
        }
        layer.confirm(ms, function(index){
            $.ajax({
                type:'get',
                url : '/setting/staff-edit',
                data :{'id':id,'is_use':status,'type':'edit'},
                dataType:'json',
                success:function(msg){
                    if (msg.code == 200) {
                        layer.close(index);
                        layer.alert('操作成功',function () {
                            location.href = '/setting/staff-list';
                        })
                    } else{
                        layer.close(index);
                        layer.alert('操作失败');
                    }
                }
            });
        });
    }
</script>